﻿using BILab.Technical.BI.Facade;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.AnalysisServices.AdomdClient;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;


namespace FacadeTest
{
    
    
    /// <summary>
    ///This is a test class for IMultidimensionalFacadeTest and is intended
    ///to contain all IMultidimensionalFacadeTest Unit Tests
    ///</summary>
    [TestClass()]
    public class IMultidimensionalFacadeTest
    {
        private TestContext testContextInstance;


        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for ConnectionString
        ///</summary>
        [Priority(100), TestMethod()]
        /* done */
        public void ConnectionStringTest()
        {
            IMultidimensionalFacade target = CreateIMultidimensionalFacade(); // TODO: Initialize to an appropriate value
            string expected = @"Provider=MSOLAP.3;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=AWBISE;Data Source=.\BILAB2005";
            string actual;
            target.ConnectionString = expected;
            actual = target.ConnectionString;
            Assert.AreEqual(expected, actual);
            //Assert.
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for getMemberTree
        ///</summary>
        [Priority(100), TestMethod()]
        public void getMemberTreeTest()
        {
            IMultidimensionalFacade target = CreateIMultidimensionalFacade(); // TODO: Initialize to an appropriate value
            TreeNode r_parentNode = null; // TODO: Initialize to an appropriate value
            TreeNode r_parentNodeExpected = null; // TODO: Initialize to an appropriate value
            string cubeName = string.Empty; // TODO: Initialize to an appropriate value
            string dimName = string.Empty; // TODO: Initialize to an appropriate value
            string hierName = string.Empty; // TODO: Initialize to an appropriate value
            string levelName = string.Empty; // TODO: Initialize to an appropriate value
            target.getMemberTree(ref r_parentNode, cubeName, dimName, hierName, levelName);
            Assert.AreEqual(r_parentNodeExpected, r_parentNode);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        ///A test for getMembers
        ///</summary>
        [Priority(15), TestMethod()]
        /* done */
        public void getMembersTest()
        {
            IMultidimensionalFacade target = CreateIMultidimensionalFacade(); // TODO: Initialize to an appropriate value
            string cubeName = "Analysis Services Tutorial"; // TODO: Initialize to an appropriate value
            string dimName = "[Product]"; // TODO: Initialize to an appropriate value
            string hierName = "Product Model Lines"; // TODO: Initialize to an appropriate value
            string levelName = "Product Line"; // TODO: Initialize to an appropriate value
            List<string> expected = new List<string>(); // TODO: Initialize to an appropriate value
            List<string> actual;

            expected.Add("Components");
            expected.Add("Mountain");
            expected.Add("Road");
            expected.Add("Accessory");
            expected.Add("Touring");
            expected.Add("Assembly Components");

            bool connected = target.Connect(target.ConnectionString);
            if (connected)
            {
              
                actual = target.getMembers(cubeName, dimName, hierName, levelName);

                Assert.IsTrue((actual.Count > 0));
                for (int i = 0; i < actual.Count; i++)
                {
                    Assert.AreEqual(actual[i], expected[i]);
                }
            }
            else
            {
                Assert.Inconclusive("Was unable to test : unable to connect");
            }            
        }

        /// <summary>
        ///A test for getLevels
        ///</summary>
        [Priority(14), TestMethod()]
        /* done */
        public void getLevelsTest()
        {
            IMultidimensionalFacade target = CreateIMultidimensionalFacade(); // TODO: Initialize to an appropriate value
            string cubeName = "Analysis Services Tutorial"; // TODO: Initialize to an appropriate value
            string dimName = "Promotion"; // TODO: Initialize to an appropriate value
            string hierName = "Promotions"; // TODO: Initialize to an appropriate value
            List<string> expected = new List<string>(); // TODO: Initialize to an appropriate value
            List<string> actual;

            expected.Add("(All)");
            expected.Add("Promotion Category");
            expected.Add("Promotion Type");
            expected.Add("Promotion Name");            
            
            bool connected = target.Connect(target.ConnectionString);
            if (connected)
            {
                actual = target.getLevels(cubeName, dimName, hierName);
                Assert.IsTrue((actual.Count > 0));
                for (int i = 0; i < actual.Count; i++)
                {
                    Assert.AreEqual(actual[i], expected[i]);
                }
            }
            else
            {
                Assert.Inconclusive("Was unable to test : unable to connect");
            }            
        }
        

        /// <summary>
        ///A test for getHierarchies
        ///</summary>
        [Priority(13), TestMethod()]
        /* done */
        public void getHierarchiesTest()
        {
            IMultidimensionalFacade target = CreateIMultidimensionalFacade(); // TODO: Initialize to an appropriate value
            string cubeName = "Analysis Services Tutorial"; // TODO: Initialize to an appropriate value
            string dimName = "Promotion"; // TODO: Initialize to an appropriate value
            List<string> expected = new List<string>(); // TODO: Initialize to an appropriate value
            List<string> actual;
            expected.Add("Discount Percentage");
            expected.Add("End Date");
            expected.Add("Maximum Quantity");
            expected.Add("Minimum Quantity");
            expected.Add("Promotion Category");
            expected.Add("Promotion Name");
            expected.Add("Promotion Type");
            expected.Add("Promotions");
            expected.Add("Start Date");


            bool connected = target.Connect(target.ConnectionString);
            if (connected)
            {
                actual = target.getHierarchies(cubeName, dimName);

                Assert.IsTrue((actual.Count > 0));
                for (int i = 0; i < actual.Count; i++)
                {
                    Assert.AreEqual(actual[i], expected[i]);
                }
            }
            else
            {
                Assert.Inconclusive("Was unable to test : unable to connect");
            }            
        }

        /// <summary>
        ///A test for GetDimensionTree
        ///</summary>
        [Priority(100), TestMethod()]
        public void GetDimensionTreeTest()
        {
            IMultidimensionalFacade target = CreateIMultidimensionalFacade(); // TODO: Initialize to an appropriate value
            string cubeName = "Analysis Services Tutorial"; // TODO: Initialize to an appropriate value
            TreeNode expected = null; // TODO: Initialize to an appropriate value
            TreeNode actual;

             bool connected = target.Connect(target.ConnectionString);

             if (connected)
             {
                 actual = target.GetDimensionTree(cubeName);
                 Assert.AreEqual(expected, actual);
             }
             else
             {
                 Assert.Inconclusive("Was unable to test : unable to connect");
             }            
        }

        /// <summary>
        ///A test for getDimension
        ///</summary>
        [Priority(12), TestMethod()]
        /* done */
        public void getDimensionTest()
        {
            IMultidimensionalFacade target = CreateIMultidimensionalFacade(); // TODO: Initialize to an appropriate value
            string cubeName = "Analysis Services Tutorial"; // TODO: Initialize to an appropriate value
            List<string> expected = new List<string>(); // TODO: Initialize to an appropriate value
            List<string> actual = null;

            expected.Add("Customer");
            expected.Add("Date");
            expected.Add("Due Date");
            expected.Add("Employee");
            expected.Add("Internet Sales Order Details");
            expected.Add("Measures");
            expected.Add("Product");
            expected.Add("Promotion");
            expected.Add("Reseller");
            expected.Add("Reseller Geography");
            expected.Add("Sales Reason");
            expected.Add("Sales Territory");
            expected.Add("Ship Date");

            bool connected = target.Connect(target.ConnectionString);

            if (connected)
            {
                actual = target.getDimension(cubeName);


                for (int i = 0; i < actual.Count; i++)
                {
                    Assert.AreEqual(actual[i], expected[i]);                  
                }
            }
            else
            {
                Assert.Inconclusive("Was unable to test : unable to connect");
            }            
            
        }

        /// <summary>
        ///A test for getDataset
        ///</summary>
        [Priority(100), TestMethod()]
        public void getDatasetTest()
        {
            IMultidimensionalFacade target = CreateIMultidimensionalFacade(); // TODO: Initialize to an appropriate value
            string mdxQuery = string.Empty; // TODO: Initialize to an appropriate value
            DataSet expected = null; // TODO: Initialize to an appropriate value
            DataSet actual;
            actual = target.getDataset(mdxQuery);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for getCubeList
        ///</summary>
        [Priority(11), TestMethod()]
        /* done */
        public void getCubeListTest()
        {
            IMultidimensionalFacade target = CreateIMultidimensionalFacade(); // TODO: Initialize to an appropriate value
            bool connected = target.Connect(target.ConnectionString);

            if (connected)
            {
                List<string> expected = new List<string>();
                expected.Add("Analysis Services Tutorial");
                expected.Add("MySample");

                List<string> actual;
                actual = target.getCubeList();
                for (int i = 0; i<actual.Count; i++)
                {
                    Assert.AreEqual(actual[i], expected[i]);
                }
            }
            else
            {
                Assert.Inconclusive("Was unable to test : unable to connect");
            }
        }

        /// <summary>
        ///A test for getCellSet
        ///</summary>
        [Priority(100), TestMethod()]
        public void getCellSetTest()
        {
            IMultidimensionalFacade target = CreateIMultidimensionalFacade(); // TODO: Initialize to an appropriate value
            string mdxQuery = string.Empty; // TODO: Initialize to an appropriate value
            CellSet expected = null; // TODO: Initialize to an appropriate value
            CellSet actual;
            actual = target.getCellSet(mdxQuery);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for Connect
        ///</summary>
        [Priority(10), TestMethod()]
        /* done */
        public void ConnectTest()
        {
            IMultidimensionalFacade target = CreateIMultidimensionalFacade(); // TODO: Initialize to an appropriate value
            string connString = target.ConnectionString; // TODO: Initialize to an appropriate value
            bool expected = true; // TODO: Initialize to an appropriate value
            bool actual;
            actual = target.Connect(connString);
            Assert.AreEqual(expected, actual);            
        }

        /* done */
        internal virtual IMultidimensionalFacade CreateIMultidimensionalFacade()
        {
            // TODO: Instantiate an appropriate concrete class.
            IMultidimensionalFacade target = new XMLAMDFacade();
            target.ConnectionString = @"Provider=MSOLAP.3;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Analysis Services Tutorial;Data Source=.\BILAB2005";
            return target;
        }

        /// <summary>
        ///A test for Close
        ///</summary>
        [Priority(200), TestMethod()]
        public void CloseTest()
        {
            IMultidimensionalFacade target = CreateIMultidimensionalFacade(); // TODO: Initialize to an appropriate value
            target.Close();
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
    }
}
